package com.yanqu.road.server.cmd.activity.pawnshop;

import com.yanqu.road.entity.activity.pawnshop.PawnshopReceptionResult;
import com.yanqu.road.pb.activity.PawnshopProto;
import com.yanqu.road.pb.activity.PawnshopProto.PawnshopEventReceptionRespMsg;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.pawnshop.PawnshopModule;
import com.yanqu.road.server.pb.PawnshopPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_PAWNSHOP_EVENT_RECEPTION, desc = "请求接待事件")
public class PawnshopEventReceptionCmd extends AbstractCommand {

    private PawnshopReceptionResult receptionResult;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {

        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        PawnshopProto.PawnshopEventReceptionReqMsg msg = PawnshopProto.PawnshopEventReceptionReqMsg.parseFrom(packet.getBytes());
        receptionResult = player.getModule(PawnshopModule.class).reception(msg.getEventType());
    }

    @Override
    public void sendData(GamePlayer player) {
        if(null != receptionResult) {
            PawnshopEventReceptionRespMsg.Builder respMsg = PawnshopEventReceptionRespMsg.newBuilder();
            respMsg.setRet(receptionResult.getRet());
            if (receptionResult.getRet() == 0) {
                respMsg.setReward(receptionResult.getReward());
                respMsg.setEvent(PawnshopPb.getDPawnshopEvent(receptionResult.getEvent()));
            }
            player.sendPacket(Protocol.U_PAWNSHOP_EVENT_RECEPTION, respMsg);
        }
    }
}
